#!/usr/bin/python
#coding=utf-8
import urllib, urllib2, socket, os, re
import time
import sys

g_city = '北京'
g_school = '和盛大厦'
g_classroom = ['201', '311', '301', '210', '405', '312', '322']

#提交函数
def post(url, data):
    data = urllib.urlencode(data)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req, timeout=5)
    return response.read()

#入口函数
def mdm_send(city, school, classroom, macaddr, battery):
    data = {}

    posturl = "http://127.0.0.1:8102/recv/mdm"

    #获取地方市的名字
    data['city'] = city

    #学校名称
    data['school'] = school

    #教室名称
    data['classroom'] = classroom

    #内存信息
    data['macaddr'] = macaddr
    data['battery'] = battery
    data['uptime'] = 3000
    data['memory'] = '459321344,2111029248'
    data['storage'] = '221184,10242949120'
    data['wifistrength'] = '-45'
    data['fmver'] = '1.0.0'
    data['devtype'] = 'lianhexun.Q896'

    ret = post(posturl, data)

    #print ret
    return ret


if __name__ == '__main__':
    for crm in g_classroom:
        ret = mdm_send(g_city, g_school, crm, '00-11-22-33-44-55', '90')
        print ret
